Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
mongoose-json-select
Advanced tools
A mongoose plugin to limit JSON properties.
var jsonSelect = require('mongoose-json-select');
var schema = Schema({
name: String,
email: String,
created: {type: Date, default: Date.now}
});
schema.plugin(jsonSelect, 'name created');
var User = mongoose.model('User', schema);
var user = User({name: 'alice', email: 'alice@example.com'});
JSON.stringify(user);
// -> '{"_id": "51466baedf03a52e9b000001", "name": "alice", "created": "2013-03-16T16:08:38.065Z"}'
JSON.stringify(user.toJSON({select: 'name email'}));
// -> '{"_id": "51466baedf03a52e9b000001", "name": "alice", "email": "alice@example.com"}'
$ npm install mongoose-json-select
Inclusion/Exclusion
// inclusion. these are equivalent
schema.plugin(jsonSelect, 'name.first');
schema.plugin(jsonSelect, {'name.first': 1});
// exclusion. these are equivalent
schema.plugin(jsonSelect, '-name.last');
schema.plugin(jsonSelect, {'name.last': 0});
Always includes _id field if the field is not excluded explicitly.
schema.plugin(jsonSelect, 'name'); // contains 'name' and '_id'
Configures default fields as a plugin option or schema option.
// these are equivalent
schema.plugin(jsonSelect, 'name');
schema.plugin(jsonSelect);
schema.set('toJSON', {select: 'name'});
Specifies fields when calling toJSON.
// this overrides a default configuration
JSON.stringify(doc.toJSON({select: 'name email'}));
The syntax for fields is the same with mongoose's Query#select.
http://mongoosejs.com/docs/api.html#query_Query-select
Creates a deep clone of 'obj' filtered by 'fields'.
var select = require('mongoose-json-select').select;
select({a: {b: 'foo'}, c: 'bar'}, 'a.b');
// -> {a: {b: 'foo'}}
MIT
FAQs
a mongoose plugin to limit json fields
We found that mongoose-json-select demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.